package com.ufgov.ip.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.ufgov.ip.entity.IpUser;

public interface IuapUserDao extends PagingAndSortingRepository<IpUser, Long>,JpaSpecificationExecutor<IpUser> {
	
	IpUser findByLoginName(String loginName);

	IpUser findUserByCellphoneNo(String cellphoneNo);

	IpUser findUserByUserEmail(String userEmail);
	
	@Query("from IpUser ih where userEmail=:loginName or loginName=:loginName or cellphoneNo=:loginName")
	IpUser findUserByUserEmailOrLoginNameOrCellphoneNo(@Param("loginName")String loginName);

	@Query("from IpUser order by employeeNo")
	List<IpUser> findUserAll();

	IpUser findIpUserByEmployeeNo(String employeeNo);
    
	
	@Modifying(clearAutomatically = true) @Query("update IpUser ipUser set ipUser.isEnabled=:isEnabled where ipUser.userId=:userId")
	void updateUserByUserId(@Param("userId")String userId, @Param("isEnabled")String isEnabled);

	@Query("from IpUser where userId=:userId and isEnabled=:isEnabled")
	IpUser findByUserIdAndisEnabled(@Param("userId")String userId, @Param("isEnabled")String isEnabled);

	IpUser findUserByUserId(String userId);
	
	@Query("from IpUser ih where (userEmail like:loginName or loginName like:loginName or cellphoneNo like:loginName) and isEnabled=:isEnabled")
	List<IpUser> findUserByUserEmailOrLoginNameOrCellphoneNoLike(@Param("loginName")String loginName, @Param("isEnabled")String isEnabled);

	@Query("from IpUser ih where ih.hirerId=:hirerId")
	List<IpUser> findUserByHirerId(@Param("hirerId")String hirerId);
	
}
